


//
//  StatusCell.m
//  kuangjia
//
//  Created by 张帅 on 15/10/2.
//  Copyright © 2015年 ZhangShuai. All rights reserved.
//

#import "StatusCell.h"
#import "UILabel+Contenlable.h"

#define HMStatusPictureItemWidth 90
#define HMStatusPictureItemMargin 10
#define HMStatusPictureMaxCount  3



@interface StatusCell ()

@end


@implementation StatusCell

-(void)setStatusViewModel:(StatusViewModel *)statusViewModel {
  
    _statusViewModel=statusViewModel;
    
    self.topView.statusViewModel= statusViewModel;
    
    self.contentLabel.text = statusViewModel.status.text;
//    
    self.pictureView.statusViewModel =statusViewModel;

    [self.pictureView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(self.pictureView.bounds.size.height));
        make.width.equalTo(@(self.pictureView.bounds.size.width));
    }];
  
    
}




-(CGFloat)rowHeight:(StatusViewModel *)viewModel{

    self.statusViewModel =viewModel;
    [self layoutIfNeeded];
    
    return CGRectGetMaxY(self.bottomView.frame);
    
    
}


// MARK: - 搭建界面
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}


-(void)setupUI{
 
    self.backgroundColor=[UIColor whiteColor];
    
    UIView *topSepView =[[UIView alloc] init];
    
    topSepView.backgroundColor = [UIColor colorWithWhite:0.85 alpha:1.0];
    
    
    [self.contentView addSubview:topSepView];
    [self.contentView addSubview:self.topView];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.pictureView];
    [self.contentView addSubview:self.bottomView];
    
    topSepView.translatesAutoresizingMaskIntoConstraints =NO;
    self.topView.translatesAutoresizingMaskIntoConstraints = NO;
    self.contentLabel.translatesAutoresizingMaskIntoConstraints =NO;
    self.pictureView.translatesAutoresizingMaskIntoConstraints =NO;
    self.bottomView.translatesAutoresizingMaskIntoConstraints =NO;
    
    
    //
    
    CGFloat width  =[UIScreen mainScreen].bounds.size.width;
   // topSepView
    
    [topSepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.contentView.mas_top);
        make.width.equalTo(@(width));
        make.height.equalTo(@(HMStatusCellMargin));
           }];

    
    //MARK: TopView
   [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.equalTo(topSepView.mas_left).offset(HMStatusCellMargin);
       
       make.top.equalTo(topSepView.mas_bottom).offset(HMStatusCellMargin);
       make.width.equalTo(@(width));
       make.height.equalTo(@(HMStatusCellMargin +HMStatusIconWidth));
       
       
   }];
    
 
    
      //MARK:contenlable

    [self.contentLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.topView.mas_left);
        make.top.equalTo(self.topView.mas_bottom).offset(HMStatusCellMargin);
        
    }];


   //MARK:BottomView
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.pictureView.mas_left).offset(-HMStatusCellMargin);
        make.top.equalTo(self.pictureView.mas_bottom).offset(HMStatusCellMargin);
        make.width.equalTo(@(width));
        make.height.equalTo(@(44));
    }];


    
    
}

-(StatusCellTopView *)topView{

    if (_topView==nil) {
        _topView =[[StatusCellTopView alloc] init];
    }
    return _topView;
}

-(StatusCellBottomView *)bottomView{
    if (_bottomView==nil) {
        
        _bottomView=[[StatusCellBottomView alloc] init];
        
        [_bottomView setBackgroundColor:[UIColor colorWithWhite:0.89 alpha:1]];
        
    }
    return _bottomView;
}


-(UILabel *)contentLabel{
    if (_contentLabel==nil) {
        
        
        _contentLabel=[[UILabel alloc] initWithTitle:nil color:[UIColor darkGrayColor] sizeFont:14 layoutWidth:[UIScreen mainScreen].bounds.size.width - 2*HMStatusCellMargin];

    }
    return _contentLabel;
    
}

-(StatusPictureView *)pictureView{

    if (_pictureView==nil) {
        _pictureView =[StatusPictureView new];
        
    }
    return _pictureView;
}
@end
